package ar.com.vates.entrada_salida_encriptacion;

import java.io.*;

public class Metdos {

	public StringBuffer desencriptar() {

		StringBuffer cadena = new StringBuffer();
		
		String str ="";

		try {
			FileReader nuevo = new FileReader("Original.DIC");
			LineNumberReader lr = new LineNumberReader(nuevo);
			while ((str =lr.readLine()) != null) {
			
				cadena.append(str.trim());
			}
		
				System.out.println(cadena.toString());	
				ayuda(cadena);

		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("error al leer el archivo");
		}
		return cadena;
	}

	private void ayuda(StringBuffer cadena) {
		StringBuffer aux1 = cadena;
		int cont = 0;
		for (int i = 0; i < cadena.length(); i++) {
			if (cadena.charAt(i) != ' ')
				aux1.setCharAt(i, (char) (cadena.charAt(i) - cont - i - 1));

			//System.out.println("Caracter en " + i + ": " + aux1.charAt(i));
			if (cadena.charAt(i) == ' ')
				cont++;
			if (cont > 7)
				cont = 0;
		}

		FileWriter nuevo;
		try {
			nuevo = new FileWriter("Nuevo.DIC");
			BufferedWriter bw = new BufferedWriter(nuevo);
			bw.write(aux1.toString());
		} catch (IOException e) {
			System.out.println("error");
			e.printStackTrace();
		}

	}

}
